package demo.controller;


import demo.dao.UserMapper;
import jdbc.InputUtil;
import jdbc.Userinfo;

import java.util.Scanner;

public class UserController {
    //注册
    private UserMapper userMapper = new UserMapper();

    public void start() {
        System.out.println("欢迎使用用户管理系统");
        System.out.println("请输入要进行操作的编号：");
        System.out.println("[1]:用户注册");
        System.out.println("[2]:用户登录");
        System.out.println("[3]:修改密码");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();
        switch (input) {
            case "1":
                regUser();
                break;
            case "2":
//                loginUser();
                break;
            case "3":
//                changePassword();
                break;
            default:
                System.out.println("编号输入有误");

        }

    }

    public void regUser() {
        Userinfo userinfo = InputUtil.getInputObject(new Userinfo(), "用户注册");
        if (userMapper.findUsername(userinfo.getUsername()) != null) {
            System.out.println("用户名已存在");
        } else {
            userMapper.insert(userinfo);

            System.out.println("注册成功");
        }

    }

//    public void loginUser(){
//
//    }
//    public void changePassword(){
//
//    }


    public static void main(String[] args) {
        UserController userController = new UserController();
        userController.start();
    }
}